package xyz.naoyu.servlets.filter;

import com.alibaba.fastjson.JSON;
import xyz.naoyu.servlets.service.impl.BackCode;
import xyz.naoyu.settings;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author yWieLoc
 * @date 2022/3/18 16:51
 */
@WebFilter(urlPatterns = {"/api/*"})
public class BaseFilter implements Filter {


    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain filterChain) throws IOException, ServletException {
        req.setCharacterEncoding("UTF-8");		// 接受到的
        resp.setContentType("text/html; charset=UTF-8");		// 修改发送的

        String action = req.getParameter("action");
        if(action == null) {
            resp.getWriter().append(JSON.toJSONString(
                    new BackCode(false, "请求不规范", null)
            ));
        } else {
            if(settings.verify.getBooleanValue(action)) {
                // 审核区

            }
            filterChain.doFilter(req,resp);
        }

    }


}
